package com.divine.wn.car.admin.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.divine.wn.car.admin.persistence.LogMapper;
import com.divine.wn.car.admin.vo.LogVO;

@Service
public class LogService {
	@Autowired
	private LogMapper logMapper;
	
	//@Transactional  在需要事务的时候加上这个标签。
	@Transactional
	public void insertLog(LogVO  logVO){
		 logMapper.insertLog(logVO);
	}
	public List<HashMap<String,Object>> getLogList(int id){
		List<HashMap<String,Object>> Logs=logMapper.getLogList(id);
		for (Iterator<HashMap<String,Object>> iterator = Logs.iterator(); iterator.hasNext();) {
			HashMap<String, Object> log = (HashMap<String, Object>) iterator.next();
			if(log.get("time_diff")!=null){
				String time_diff=log.get("time_diff").toString();
				String[] times=time_diff.split(":");
			
				Integer x=new Integer(times[0])/24;
				log.put("date", x+"");
				log.put("hour", new Integer(times[0])%24+"");
				log.put("minute", new Integer(times[1])+"");
				log.put("second", new Integer(times[2])+"");
			}else{
				log.put("date", "0");
				log.put("hour", "0");
				log.put("minute", "0");
				log.put("second", "0");
			}
			
			
			
			
		}
		return Logs;
	}

}
